package ciyuan.Gui.Component;

import ciyuan.MainClass;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;

public class ItemButton extends Button {

    private static final ResourceLocation BACKGROUND = new ResourceLocation(MainClass.MODID, "textures/gui/container/slot.png");
    private final Item item;
    private final int left;
    private final int top;
    private final ItemRenderer itemRenderer;

    public ItemButton(int left, int top, ITextComponent iTextComponent, Item item, IPressable iPressable, ItemRenderer itemRenderer) {
        super(left, top, 18, 18, iTextComponent, iPressable);
        this.left = left;
        this.top = top;
        this.item = item;
        this.itemRenderer = itemRenderer;
    }

    @Override
    public void renderButton(MatrixStack matrixStack, int mouseX, int mouseY, float particleTick) {
        this.renderBg(matrixStack, Minecraft.getInstance(), mouseX, mouseY);
        this.itemRenderer.renderAndDecorateItem(item.getDefaultInstance(), this.left + 1, this.top + 1);
    }

    @Override
    protected void renderBg(MatrixStack matrixStack, Minecraft minecraft, int mouseX, int mouseY) {
        minecraft.getTextureManager().bind(BACKGROUND);
        RenderSystem.color4f(1.0F, 1.0F, 1.0F, this.alpha);
        blit(matrixStack, this.x, this.y, 0, 0, width, height, width, height);
    }
}
